Socket
Socket
Sign inDemoInstall

object-to-spawn-args

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-to-spawn-args

Converts an object to a child_process.spawn args array


Version published
Weekly downloads
155K
increased by1.34%
Maintainers
1
Weekly downloads
 
Created
Source

view on npm npm module downloads Gihub repo dependents Gihub package dependents Build Status js-standard-style

object-to-spawn-args

Converts an options object to an array suitable for passing to child_process.spawn().

Single letter object properties (e.g. c: 'red') convert to short-option args (e.g. -c red). Longer object properties (e.g. colour: 'red') convert to long-option args (e.g. --colour red). Object property values equalling true convert to flags (e.g. -l).

Synopsis

Simple usage:

> const objectToSpawnArgs = require('object-to-spawn-args')

> const spawnArgs = objectToSpawnArgs({
  l: true,
  c: 'red',
  name: 'pete',
  tramp: true
})

> console.log(spawnArgs)
[ '-l', '-c', 'red', '--name', 'pete', '--tramp' ]

Alternatively, convert to --object=value notation.

> const options = {
  l: true,
  c: 'red',
  name: 'pete',
  tramp: true
}
> const spawnArgs = objectToSpawnArgs(options, { optionEqualsValue: true })

> console.log(spawnArgs)
[ '-l', '-c=red', '--name=pete', '--tramp' ]

Typical real-life example.

const objectToSpawnArgs = require('object-to-spawn-args')
const spawn = require('child_process').spawn

const options = {
  l: true,
  a: true
}

spawn('ls', objectToSpawnArgs(options), { stdio: 'inherit' })

Installation

$ npm install object-to-spawn-args

© 2014-21 Lloyd Brookes <75pound@gmail.com>.

Keywords

FAQs

Package last updated on 13 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc